import { _decorator, Node, input, Input, Vec2, geometry, Camera, PhysicsSystem, EventTouch, v3, Component } from 'cc';
import { HexagonJenga_EventName, HexagonJenga_main } from './HexagonJenga_main';
// import { EventName } from './eventManager';
// import { EventName, main } from '../main';

const { ccclass, property } = _decorator;
/**
 * 射线碰撞检测
 */
@ccclass('HexagonJenga_screenRayCmpt')
export class HexagonJenga_screenRayCmpt extends Component {
    private isCanDo: boolean = true;
    onLoad() {
        // super.onLoad();
    }
    start() {
        input.on(Input.EventType.TOUCH_START, this.onTouchStart, this);
        input.on(Input.EventType.TOUCH_MOVE, this.onTouchMove, this);
        input.on(Input.EventType.TOUCH_END, this.onTouchEnd, this);
    }

    onTouchStart(event: EventTouch) {
        // console.log("onTouchStart");

        if (!this.isCanDo) {
            this.isCanDo = true;
            return;
        }
        // eventMgt.emit(EventName.TouchStart, event.getUILocation());

        HexagonJenga_main.Instance.node.emit(HexagonJenga_EventName.TouchStart, event.getUILocation());
    }

    onTouchMove(event: EventTouch) {
        // console.log("onTouchMove");
        if (!this.isCanDo) return;
        // eventMgt.emit(EventName.TouchMove, event.getUILocation());

        HexagonJenga_main.Instance.node.emit(HexagonJenga_EventName.TouchMove, event.getUILocation());

    }


    onTouchEnd(event: EventTouch) {
        // console.log("onTouchEnd");
        this.isCanDo = true;
        // eventMgt.emit(EventName.TouchEnd, event.getUILocation());

        HexagonJenga_main.Instance.node.emit(HexagonJenga_EventName.TouchEnd, event.getUILocation());

    }
}